<?php

namespace app\controller;

use app\BaseController;
use think\helper\Str;

class ApiBase extends BaseController
{
    public function index()
    {
        try {
            $con = $this->request->param("cont");
            $fn = $this->request->param("fn");
            //驼峰名
            $con = Str::studly($con);
            $con = "\\app\\controller\\api\\$con";
            if (!class_exists($con)) throw new \Exception("请求方式不存在", 7002);
            if (!method_exists($con, $fn)) throw new \Exception("请求方法不存在", 7003);
            return $this->app->make($con)->{$fn}();
        } catch (\Exception $e) {
            return $this->error($e->getMessage(), $e->getCode());
        }
    }
}
